using System;
using System.Threading;
using NUnit.Framework;

namespace DZTC.Base32Utility.Tests
{
    [TestFixture]
    internal class CancellationTests
    {
        [Test]
        public void BasicTest()
        {
            var cts = new CancellationTokenSource();
            var tok = cts.Token;

            Assert.AreEqual(false, tok.IsCancellationRequested);
            tok.ThrowIfCancellationRequested();

            cts.Cancel();

            Assert.AreEqual(true, tok.IsCancellationRequested);
            Assert.Throws<OperationCanceledException>(tok.ThrowIfCancellationRequested);
        }

        [Test]
        public void TestNone()
        {
            var tok = CancellationToken.None;

            Assert.AreEqual(false, tok.IsCancellationRequested);
            tok.ThrowIfCancellationRequested();
        }

        [Test]
        public void TestDefault()
        {
            var tok = default(CancellationToken);

            Assert.AreEqual(false, tok.IsCancellationRequested);
            tok.ThrowIfCancellationRequested();
        }
    }
}